$(function () {
  getBanner();
});

function getBanner() {
  getData('/v1/plan/banner', {
    page: 1,
    size: 20,
    t: 1576725553574
  }).then((data) => {
    createBanner(data.data)
  }).catch((error) => {
    console.log('banner请求错误：')
    console.log(error)
  });
}

function createBanner(list) {
  let bannerHtml = ``
  list.forEach((item) => {
    bannerHtml += `
      <div class="swiper-slide">
        <img src="${item.image}">
      </div>
    `
  });
  $('.index-banner .swiper-wrapper').append(bannerHtml)
  var bannerSwiper = new Swiper('.index-banner .swiper-container', {
    on: {
      init: function () {
        swiperAnimateCache(this); //隐藏动画元素 
        this.emit('slideChangeTransitionEnd'); //在初始化时触发一次slideChangeTransitionEnd事件
      },
      slideChangeTransitionEnd: function () {
        swiperAnimate(this); //每个slide切换结束时运行当前slide动画
        this.slides.eq(this.activeIndex).find('.ani').removeClass('ani'); //动画只展示一次
      }
    },
    loop: true,
    autoplay: {
      delay: 3000,
      stopOnLastSlide: false,
      disableOnInteraction: true
    },
    pagination: {
      el: '.swiper-pagination',
      type: 'fraction'
    }
  });
}